/**
 * This is a generated class and is not intended for modification.  To customize behavior
 * of this value object you may modify the generated sub-class of this class - GetAllObservationsForSpeciesResponse.as.
 */

package valueObjects
{
import com.adobe.fiber.services.IFiberManagingService;
import com.adobe.fiber.util.FiberUtils;
import com.adobe.fiber.valueobjects.IValueObject;
import flash.events.Event;
import flash.events.EventDispatcher;
import mx.binding.utils.ChangeWatcher;
import mx.collections.ArrayCollection;
import mx.events.CollectionEvent;
import mx.events.PropertyChangeEvent;
import mx.validators.ValidationResult;
import valueObjects.Observation_type;
import valueObjects.Phenophase_type;
import valueObjects.Station_type;

import flash.net.registerClassAlias;
import flash.net.getClassByAlias;
import com.adobe.fiber.core.model_internal;
import com.adobe.fiber.valueobjects.IPropertyIterator;
import com.adobe.fiber.valueobjects.AvailablePropertyIterator;

use namespace model_internal;

[ExcludeClass]
public class _Super_GetAllObservationsForSpeciesResponse extends flash.events.EventDispatcher implements com.adobe.fiber.valueobjects.IValueObject
{
    model_internal static function initRemoteClassAliasSingle(cz:Class) : void
    {
    }

    model_internal static function initRemoteClassAliasAllRelated() : void
    {
        valueObjects.Station_type.initRemoteClassAliasSingleChild();
        valueObjects.Phenophase_type.initRemoteClassAliasSingleChild();
        valueObjects.Observation_type.initRemoteClassAliasSingleChild();
        valueObjects.Stations_type.initRemoteClassAliasSingleChild();
        valueObjects.Species_ids_type.initRemoteClassAliasSingleChild();
        valueObjects.Phenophases_type.initRemoteClassAliasSingleChild();
    }

    model_internal var _dminternal_model : _GetAllObservationsForSpeciesResponseEntityMetadata;
    model_internal var _changedObjects:mx.collections.ArrayCollection = new ArrayCollection();

    public function getChangedObjects() : Array
    {
        _changedObjects.addItemAt(this,0);
        return _changedObjects.source;
    }

    public function clearChangedObjects() : void
    {
        _changedObjects.removeAll();
    }

    /**
     * properties
     */
    private var _internal_station_list : ArrayCollection;
    model_internal var _internal_station_list_leaf:valueObjects.Station_type;
    private var _internal_phenophase_list : ArrayCollection;
    model_internal var _internal_phenophase_list_leaf:valueObjects.Phenophase_type;
    private var _internal_observation_list : ArrayCollection;
    model_internal var _internal_observation_list_leaf:valueObjects.Observation_type;

    private static var emptyArray:Array = new Array();


    /**
     * derived property cache initialization
     */
    model_internal var _cacheInitialized_isValid:Boolean = false;

    model_internal var _changeWatcherArray:Array = new Array();

    public function _Super_GetAllObservationsForSpeciesResponse()
    {
        _model = new _GetAllObservationsForSpeciesResponseEntityMetadata(this);

        // Bind to own data or source properties for cache invalidation triggering
        model_internal::_changeWatcherArray.push(mx.binding.utils.ChangeWatcher.watch(this, "station_list", model_internal::setterListenerStation_list));
        model_internal::_changeWatcherArray.push(mx.binding.utils.ChangeWatcher.watch(this, "phenophase_list", model_internal::setterListenerPhenophase_list));
        model_internal::_changeWatcherArray.push(mx.binding.utils.ChangeWatcher.watch(this, "observation_list", model_internal::setterListenerObservation_list));

    }

    /**
     * data/source property getters
     */

    [Bindable(event="propertyChange")]
    public function get station_list() : ArrayCollection
    {
        return _internal_station_list;
    }

    [Bindable(event="propertyChange")]
    public function get phenophase_list() : ArrayCollection
    {
        return _internal_phenophase_list;
    }

    [Bindable(event="propertyChange")]
    public function get observation_list() : ArrayCollection
    {
        return _internal_observation_list;
    }

    public function clearAssociations() : void
    {
    }

    /**
     * data/source property setters
     */

    public function set station_list(value:*) : void
    {
        var oldValue:ArrayCollection = _internal_station_list;
        if (oldValue !== value)
        {
            if (value is ArrayCollection)
            {
                _internal_station_list = value;
            }
            else if (value is Array)
            {
                _internal_station_list = new ArrayCollection(value);
            }
            else if (value == null)
            {
                _internal_station_list = null;
            }
            else
            {
                throw new Error("value of station_list must be a collection");
            }
            this.dispatchEvent(mx.events.PropertyChangeEvent.createUpdateEvent(this, "station_list", oldValue, _internal_station_list));
        }
    }

    public function set phenophase_list(value:*) : void
    {
        var oldValue:ArrayCollection = _internal_phenophase_list;
        if (oldValue !== value)
        {
            if (value is ArrayCollection)
            {
                _internal_phenophase_list = value;
            }
            else if (value is Array)
            {
                _internal_phenophase_list = new ArrayCollection(value);
            }
            else if (value == null)
            {
                _internal_phenophase_list = null;
            }
            else
            {
                throw new Error("value of phenophase_list must be a collection");
            }
            this.dispatchEvent(mx.events.PropertyChangeEvent.createUpdateEvent(this, "phenophase_list", oldValue, _internal_phenophase_list));
        }
    }

    public function set observation_list(value:*) : void
    {
        var oldValue:ArrayCollection = _internal_observation_list;
        if (oldValue !== value)
        {
            if (value is ArrayCollection)
            {
                _internal_observation_list = value;
            }
            else if (value is Array)
            {
                _internal_observation_list = new ArrayCollection(value);
            }
            else if (value == null)
            {
                _internal_observation_list = null;
            }
            else
            {
                throw new Error("value of observation_list must be a collection");
            }
            this.dispatchEvent(mx.events.PropertyChangeEvent.createUpdateEvent(this, "observation_list", oldValue, _internal_observation_list));
        }
    }

    /**
     * Data/source property setter listeners
     *
     * Each data property whose value affects other properties or the validity of the entity
     * needs to invalidate all previously calculated artifacts. These include:
     *  - any derived properties or constraints that reference the given data property.
     *  - any availability guards (variant expressions) that reference the given data property.
     *  - any style validations, message tokens or guards that reference the given data property.
     *  - the validity of the property (and the containing entity) if the given data property has a length restriction.
     *  - the validity of the property (and the containing entity) if the given data property is required.
     */

    model_internal function setterListenerStation_list(value:flash.events.Event):void
    {
        if (value is mx.events.PropertyChangeEvent)
        {
            if (mx.events.PropertyChangeEvent(value).newValue)
            {
                mx.events.PropertyChangeEvent(value).newValue.addEventListener(mx.events.CollectionEvent.COLLECTION_CHANGE, model_internal::setterListenerStation_list);
            }
        }
        _model.invalidateDependentOnStation_list();
    }

    model_internal function setterListenerPhenophase_list(value:flash.events.Event):void
    {
        if (value is mx.events.PropertyChangeEvent)
        {
            if (mx.events.PropertyChangeEvent(value).newValue)
            {
                mx.events.PropertyChangeEvent(value).newValue.addEventListener(mx.events.CollectionEvent.COLLECTION_CHANGE, model_internal::setterListenerPhenophase_list);
            }
        }
        _model.invalidateDependentOnPhenophase_list();
    }

    model_internal function setterListenerObservation_list(value:flash.events.Event):void
    {
        if (value is mx.events.PropertyChangeEvent)
        {
            if (mx.events.PropertyChangeEvent(value).newValue)
            {
                mx.events.PropertyChangeEvent(value).newValue.addEventListener(mx.events.CollectionEvent.COLLECTION_CHANGE, model_internal::setterListenerObservation_list);
            }
        }
        _model.invalidateDependentOnObservation_list();
    }


    /**
     * valid related derived properties
     */
    model_internal var _isValid : Boolean;
    model_internal var _invalidConstraints:Array = new Array();
    model_internal var _validationFailureMessages:Array = new Array();

    /**
     * derived property calculators
     */

    /**
     * isValid calculator
     */
    model_internal function calculateIsValid():Boolean
    {
        var violatedConsts:Array = new Array();
        var validationFailureMessages:Array = new Array();

        var propertyValidity:Boolean = true;
        if (!_model.station_listIsValid)
        {
            propertyValidity = false;
            com.adobe.fiber.util.FiberUtils.arrayAdd(validationFailureMessages, _model.model_internal::_station_listValidationFailureMessages);
        }
        if (!_model.phenophase_listIsValid)
        {
            propertyValidity = false;
            com.adobe.fiber.util.FiberUtils.arrayAdd(validationFailureMessages, _model.model_internal::_phenophase_listValidationFailureMessages);
        }
        if (!_model.observation_listIsValid)
        {
            propertyValidity = false;
            com.adobe.fiber.util.FiberUtils.arrayAdd(validationFailureMessages, _model.model_internal::_observation_listValidationFailureMessages);
        }

        model_internal::_cacheInitialized_isValid = true;
        model_internal::invalidConstraints_der = violatedConsts;
        model_internal::validationFailureMessages_der = validationFailureMessages;
        return violatedConsts.length == 0 && propertyValidity;
    }

    /**
     * derived property setters
     */

    model_internal function set isValid_der(value:Boolean) : void
    {
        var oldValue:Boolean = model_internal::_isValid;
        if (oldValue !== value)
        {
            model_internal::_isValid = value;
            _model.model_internal::fireChangeEvent("isValid", oldValue, model_internal::_isValid);
        }
    }

    /**
     * derived property getters
     */

    [Transient]
    [Bindable(event="propertyChange")]
    public function get _model() : _GetAllObservationsForSpeciesResponseEntityMetadata
    {
        return model_internal::_dminternal_model;
    }

    public function set _model(value : _GetAllObservationsForSpeciesResponseEntityMetadata) : void
    {
        var oldValue : _GetAllObservationsForSpeciesResponseEntityMetadata = model_internal::_dminternal_model;
        if (oldValue !== value)
        {
            model_internal::_dminternal_model = value;
            this.dispatchEvent(mx.events.PropertyChangeEvent.createUpdateEvent(this, "_model", oldValue, model_internal::_dminternal_model));
        }
    }

    /**
     * methods
     */


    /**
     *  services
     */
    private var _managingService:com.adobe.fiber.services.IFiberManagingService;

    public function set managingService(managingService:com.adobe.fiber.services.IFiberManagingService):void
    {
        _managingService = managingService;
    }

    model_internal function set invalidConstraints_der(value:Array) : void
    {
        var oldValue:Array = model_internal::_invalidConstraints;
        // avoid firing the event when old and new value are different empty arrays
        if (oldValue !== value && (oldValue.length > 0 || value.length > 0))
        {
            model_internal::_invalidConstraints = value;
            _model.model_internal::fireChangeEvent("invalidConstraints", oldValue, model_internal::_invalidConstraints);
        }
    }

    model_internal function set validationFailureMessages_der(value:Array) : void
    {
        var oldValue:Array = model_internal::_validationFailureMessages;
        // avoid firing the event when old and new value are different empty arrays
        if (oldValue !== value && (oldValue.length > 0 || value.length > 0))
        {
            model_internal::_validationFailureMessages = value;
            _model.model_internal::fireChangeEvent("validationFailureMessages", oldValue, model_internal::_validationFailureMessages);
        }
    }

    model_internal var _doValidationCacheOfStation_list : Array = null;
    model_internal var _doValidationLastValOfStation_list : ArrayCollection;

    model_internal function _doValidationForStation_list(valueIn:Object):Array
    {
        var value : ArrayCollection = valueIn as ArrayCollection;

        if (model_internal::_doValidationCacheOfStation_list != null && model_internal::_doValidationLastValOfStation_list == value)
           return model_internal::_doValidationCacheOfStation_list ;

        _model.model_internal::_station_listIsValidCacheInitialized = true;
        var validationFailures:Array = new Array();
        var errorMessage:String;
        var failure:Boolean;

        var valRes:ValidationResult;
        if (_model.isStation_listAvailable && _internal_station_list == null)
        {
            validationFailures.push(new ValidationResult(true, "", "", "station_list is required"));
        }

        model_internal::_doValidationCacheOfStation_list = validationFailures;
        model_internal::_doValidationLastValOfStation_list = value;

        return validationFailures;
    }
    
    model_internal var _doValidationCacheOfPhenophase_list : Array = null;
    model_internal var _doValidationLastValOfPhenophase_list : ArrayCollection;

    model_internal function _doValidationForPhenophase_list(valueIn:Object):Array
    {
        var value : ArrayCollection = valueIn as ArrayCollection;

        if (model_internal::_doValidationCacheOfPhenophase_list != null && model_internal::_doValidationLastValOfPhenophase_list == value)
           return model_internal::_doValidationCacheOfPhenophase_list ;

        _model.model_internal::_phenophase_listIsValidCacheInitialized = true;
        var validationFailures:Array = new Array();
        var errorMessage:String;
        var failure:Boolean;

        var valRes:ValidationResult;
        if (_model.isPhenophase_listAvailable && _internal_phenophase_list == null)
        {
            validationFailures.push(new ValidationResult(true, "", "", "phenophase_list is required"));
        }

        model_internal::_doValidationCacheOfPhenophase_list = validationFailures;
        model_internal::_doValidationLastValOfPhenophase_list = value;

        return validationFailures;
    }
    
    model_internal var _doValidationCacheOfObservation_list : Array = null;
    model_internal var _doValidationLastValOfObservation_list : ArrayCollection;

    model_internal function _doValidationForObservation_list(valueIn:Object):Array
    {
        var value : ArrayCollection = valueIn as ArrayCollection;

        if (model_internal::_doValidationCacheOfObservation_list != null && model_internal::_doValidationLastValOfObservation_list == value)
           return model_internal::_doValidationCacheOfObservation_list ;

        _model.model_internal::_observation_listIsValidCacheInitialized = true;
        var validationFailures:Array = new Array();
        var errorMessage:String;
        var failure:Boolean;

        var valRes:ValidationResult;
        if (_model.isObservation_listAvailable && _internal_observation_list == null)
        {
            validationFailures.push(new ValidationResult(true, "", "", "observation_list is required"));
        }

        model_internal::_doValidationCacheOfObservation_list = validationFailures;
        model_internal::_doValidationLastValOfObservation_list = value;

        return validationFailures;
    }
    

}

}
